(async function(){
    var salary;
    var rtn = await loadManbers();
    if (rtn){
        salary = getNode("detail.js").tag;
        //受益人
        setNodeText("member",getMemberByAddress(salary.member).name);
        //理由
        setNodeText("reason",salary.reason);
        //周期
        var period = "";
        if (salary.period.toNumber()==0) period="单次";
        else if (salary.period.toNumber()==86400) period="每日";
        else if (salary.period.toNumber()==2635200) period="每月";
        else if (salary.period.toNumber()==31557600) period="每年";
        setNodeText("period",period);
        //金额
        setNodeText("amount",format(salary.amount));
        //开始
        setNodeText("start",dateFormat(salary.start));
        //结束
        if (salary.end.toNumber()!=0){
            setNodeText("end",dateFormat(salary.end));
        }
        //最后支付日期
        if (salary.lastPay.toNumber()!=salary.start.toNumber()){
            setNodeText("lastPay",dateFormat(salary.lastPay));
        }
        //批准者
        var f=false;
        var approver = getNode("approver");
        for(var i=0;i<salary.approver.length;i++){
            if (salary.approver[i]==publicParam.address) {
                f=true;
            }
            approver.innerHTML += getMemberByAddress(salary.approver[i]).name + " ";
        }
        var admin = await isTreasuryAdmin();
        if (admin && !f && !salary.active){
            display("isAdmin",true);
            getNode("sent").onclick=async function(){
                setLoading(1);
                const rtn = await salaryApprove("批准此项薪酬支付方案",salary.id);
                if (rtn){
                    salary.approved = true;
                    salary.active = true;
                }
                display("isAdmin",false);
                setLoading(0);
            };
        }
        //返回按钮
        getNode("goback").onclick=function(){
            goto("salary/list");
        };
    }
})();